from datetime import datetime
from tortoise import fields
from .base import BaseModel, TimestampMixin
from enum import Enum


class SexEnum(str, Enum):
    MALE = "0"
    FEMALE = "1"
    UNKNOWN = "2"


class StatusEnum(str, Enum):
    EXIST = "0"
    DELETED = "2"


class UseFlagEnum(str, Enum):
    NORMAL = "0"
    DISABLED = "1"


class SysUser(BaseModel, TimestampMixin):
    user_id = fields.IntField(pk=True, description="用户ID")
    dept_id = fields.IntField(null=True, description="部门ID")
    user_name = fields.CharField(max_length=30, null=True, description="用户账号")
    nick_name = fields.CharField(max_length=30, null=True, description="用户昵称")
    user_type = fields.CharField(max_length=2, default="00", description="用户类型")
    email = fields.CharField(max_length=50, default="", description="用户邮箱")
    phonenumber = fields.CharField(max_length=11, default="", description="手机号码")
    sex = fields.CharEnumField(SexEnum, default=SexEnum.UNKNOWN, description="用户性别")
    avatar = fields.CharField(max_length=100, default="", description="头像地址")
    password = fields.CharField(max_length=100, default="", description="密码")
    status = fields.CharEnumField(StatusEnum, default=StatusEnum.EXIST, description="状态")
    use_flag = fields.CharEnumField(UseFlagEnum, default=UseFlagEnum.NORMAL, description="使用状态")
    login_ip = fields.CharField(max_length=128, default="", description="最后登录IP")
    login_date = fields.DatetimeField(null=True, description="最后登录时间")
    create_by = fields.CharField(max_length=64, default="", description="创建者")
    update_by = fields.CharField(max_length=64, default="", description="更新者")
    remark = fields.CharField(max_length=500, null=True, description="备注")

    class Meta:
        table = "sys_user"

    def __str__(self):
        return f"{self.user_name}"